#! /usr/bin/env python
# -*- coding: utf-8 -*-

import requests
from PIL import Image

x = [850, 851, 852, 853, 854, 855, 856]
y = [419, 420, 421, 422, 423, 424, 425]
z = 10
picSize = 256

# 下载图片
for xi in x:
    for yi in y:
        url = "http://wprd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={}&y={}&z=10".format(xi, yi)
        fileName = r"E:\PycharmProjects\nlptf\3dKmean\pic\/x={}y={}z={}.png".format(xi, yi, 10)
        r = requests.get(url=url)
        with open(fileName, 'wb') as f:
            for chunk in r:
                f.write(chunk)

# 构造平图矩阵
li = []

for xi in x:
    lis = []
    for yi in y:
        fileName = "x={}y={}z={}.png".format(xi, yi, 10)
        lis.append(fileName)

    li.append(lis)

##############################################################################################################################

oca = 7

toImage = Image.new('RGBA', (oca * picSize, oca * picSize))

for i in range(oca):
    for j in range(oca):
        print(li[i][j])
        fromImge = Image.open(li[i][j])
        picx = 256 * i

        picy = 256 * j
        loc = (picx, picy)

        print(loc)

        toImage.paste(fromImge, loc)

toImage.save(r"E:\PycharmProjects\nlptf\3dKmean\pic\合并.png")
